<?php 
include_once "../library/Controller.php";

class Ingame extends Controller
{
	function __construct()
	{
		//important to call initialize superclass
		parent::__construct();

		// use data to store the GET method
		$data 	= $_GET;

		$this->view = $data['view'] ? $data['view'] : 'ricky_view.php';
		$this->map = $data['map'] ? $data['map'] : 'default_small';

		$action = $data['action'];
		$this->loadLibrary('Map.php');
		$this->loadLibrary('Players.php');
		$this->loadLibrary('State.php');

		$this->refreshTime = $data['refreshTime'];

	}

	function run()
	{
		$data = array();
		$data['title'] = "Ingame";

		$data['map'] 		= Map::getMap($this->map);
		$data['players']  	= Players::getPlayers();
		$data['playersJSON']  	= json_encode($data['players']);
		$data['state'] 	= State::getState();
		$data['playerStateJSON'] = json_encode(State::getState());
		$data['stateTree'] = State::$stateTree;
		$data['refreshTime'] = $this->refreshTime;

		// display the users view
		$this->load($this->view, $data);
	}

	function getJSON()
	{
		$obj = new ReturnMessage;
		return json_encode($obj);
	}

}

class ReturnMessage
{
	function __construct()
	{
		$this->something = "sdfdsf";
		//$this->playersJSON = Players::getPlayers();
		//$this->gameStateJSON = State::getState();
	}

}

$data = $_GET;

// execute the class
$self = new Ingame();

if ($data['json'] == 1)
{
	//$obj = $self->getJSON();
	echo "sdfsdf";
}
else $self->run();

